package org.bigdata.framework.admin.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bigdata.framework.admin.web.util.CommonUrl;
import org.bigdata.framework.core.model.BaikeCategory;
import org.bigdata.framework.core.model.BaikeEntry;
import org.bigdata.framework.core.model.BaikeEntryVersion;
import org.bigdata.framework.core.model.BaikeNews;
import org.bigdata.framework.core.model.BaikeTemplate;
import org.bigdata.framework.core.protocol.IBaikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xxl.conf.core.XxlConfClient;

@Controller
public class BaikeController extends BaseContoroller {

	@Autowired
	private IBaikeService baikeService;

	// 知识百科管理 -->分类管理树形菜单列表
	@RequestMapping("baikeCategory-menu.html")
	public String toSetting() {

		return "/modules/baike/baikeCategory_menu";
	}

	// 知识百科管理 -->分类管理树形菜单树
	@RequestMapping("baikeCategory_menu_zree.html")
	public String toZree() {

		return "/modules/baike/baikeCategory_menu_zree";
	}

	// 知识百科管理 -->分类管理树形菜单修改列表
	@RequestMapping("baikeCategory_menu_upload.html")
	public String toBaikeCategoryUpload() {

		return "/modules/baike/baikeCategory_menu_upload";
	}

	// 知识百科管理 -->分类管理树形菜单添加列表
	@RequestMapping("baikeCategory_menu_add.html")
	public String toBaikeCategory() {

		return "/modules/baike/baikeCategory_menu_add";
	}

	// 知识百科管理 -->分类管理树形菜单添加右侧
	@RequestMapping("baikeCategory_model_add.html")
	public String toBaikeCategoryModel() {

		return "/modules/baike/baikeCategory_model_add";
	}

	// 知识百科管理 -->分类管理树形菜单添加右侧
	@RequestMapping("baikeCategory_model_upload.html")
	public String toBaikeCategoryModelUpload() {

		return "/modules/baike/baikeCategory_model_upload";
	}
	
	// 知识百科管理 -->模板管理
	@RequestMapping("baikeCategory-model-organization.html")
	public String toBaiKeModel() {

		return "/modules/baike/baikeCategory_model_organization";
	}
	// 知识百科管理 -->模板管理树形菜单树
	@RequestMapping("baikeCategory_model_zree.html")
	public String toModelZree() {

		return "/modules/baike/baikeCategory_model_zree";
	}

	// 知识百科管理 -->词条查询
	@RequestMapping("baikeCategory-entry-organization.html")
	public ModelAndView toBaiKeEntry() {
	    String baikeip =  XxlConfClient.get("sso.client.host.baike", "")+"nm-framework-web-baike/";
	    ModelAndView view = new ModelAndView();
        view.addObject("baikeip", baikeip);
        view.setViewName("/modules/baike/baikeCategory_entry_organization");
        return view;
	}
	// 知识百科管理 -->新闻查询
	@RequestMapping("baikeCategory-news.html")
	public String toBaiKeNews() {
		
		return "/modules/baike/baikeCategory_news";
	}
	// 知识百科管理 -->新闻新增或修改
	@RequestMapping("baikeCategory-news-addUpload.html")
	public String toBaikeCategoryNewsAddUpload() {
		
		return "/modules/baike/baikeCategory_news_addUpload";
	}
	// 知识百科管理 -->查询所有版本
	@RequestMapping("baikeCategory-organization-history.html")
	public ModelAndView toBaikeCategoryOrganizationHistory() {
	    String baikeip =  XxlConfClient.get("sso.client.host.baike", "")+"nm-framework-web-baike/";
        ModelAndView view = new ModelAndView();
        view.addObject("baikeip", baikeip);
        view.setViewName("/modules/baike/baikeCategory_organization_history");
        return view;
	}

	// 知识百科管理 -->分类管理树形菜单列表-->查询菜单
	@RequestMapping("baikeCategoryQueryMent")
	public void toBaikeCategoryQueryMent(HttpServletResponse response)
			throws Exception {

		List<BaikeCategory> list = baikeService.getBaikeCategory();
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		for (int i = 0; i < list.size(); i++) {
			BaikeCategory baikeCategory = list.get(i);
			mp = new LinkedHashMap<String, Object>();
			mp.put("id", baikeCategory.getId());
			mp.put("name", baikeCategory.getNameZh());
			mp.put("pId", baikeCategory.getPid());
			r.add(mp);
		}
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识百科管理 -->分类管理树形菜单列表-->添加分类菜单
	@RequestMapping("baikeCategoryAddMent")
	public void toBaikeCategoryAddMent(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String nameEn = request.getParameter("nameEn");
		String nameZh = request.getParameter("nameZh");
		String sid = request.getParameter("sid");
		String sort = request.getParameter("sort");
		String pid = request.getParameter("pid");
		String icon = request.getParameter("icon");
		BaikeCategory baikeCategory = new BaikeCategory();
		baikeCategory.setNameEn(nameEn);
		baikeCategory.setNameZh(nameZh);
		baikeCategory.setSid(sid);
		baikeCategory.setIcon(icon);
		baikeCategory.setSort(Integer.parseInt(sort));
		baikeCategory.setPid(Integer.parseInt(pid));
		baikeService.saveBaikeCategory(baikeCategory);

		String result = formatToJson(baikeCategory);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识百科管理 -->分类管理树形菜单列表-->修改菜单
	@RequestMapping("baikeCategoryUploadMent")
	public void toBaikeCategoryUploadMent(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		String nameEn = request.getParameter("nameEn");
		String nameZh = request.getParameter("nameZh");
		String sid = request.getParameter("sid");
		String icon = request.getParameter("icon");
		int sort = Integer.parseInt(request.getParameter("sort"));
		int pid = Integer.parseInt(request.getParameter("pid"));
		BaikeCategory baikeCategory = baikeService.findBaikeCategory(id);
		baikeCategory.setNameZh(nameZh);
		baikeCategory.setNameEn(nameEn);
		baikeCategory.setSort(sort);
		baikeCategory.setSid(sid);
		baikeCategory.setIcon(icon);
		baikeCategory.setPid(pid);
		baikeService.editBaikeCategory(baikeCategory);

		String result = formatToJson(baikeCategory);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识百科管理 -->分类管理树形菜单列表-->修改菜单查询方法
	@RequestMapping("baikeCategoryUploadEditMent")
	public void toBaikeCategoryUploadEditMent(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		LinkedHashMap<String, Object> mp = new LinkedHashMap<String, Object>();
		BaikeCategory baikeCategory = baikeService.findBaikeCategory(id);
		if (baikeCategory.getPid() == 0) {
				mp.put("parentName", "根目录");
			} else {
				BaikeCategory list = baikeService.findBaikeCategory(baikeCategory.getPid());
				mp.put("parentName", list.getNameZh());
			}
		
		mp.put("nameEn", baikeCategory.getNameEn());
		mp.put("sid", baikeCategory.getSid());
		mp.put("nameZh", baikeCategory.getNameZh());
		mp.put("pid", baikeCategory.getPid());
		mp.put("sort", baikeCategory.getSort());
		mp.put("icon", baikeCategory.getIcon());
		String result = formatToJson(mp);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识百科管理 -->分类管理树形菜单列表-->删除菜单
	@RequestMapping("baikeCategoryDeleteMent")
	public void toBaikeCategoryDeleteMent(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		int id = Integer.parseInt(request.getParameter("id"));
		BaikeCategory baikeCategory = baikeService.findBaikeCategory(id);
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		queryParams.put("=,sid", baikeCategory.getSid());
		int count = baikeService.getBaikeTemplateCount(queryParams);
		if(count == 0){
			baikeService.deleteBaikeCategory(baikeCategory);
		}
		List<Integer> r = new ArrayList<Integer>();
		r.add(count);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识百科管理 -->模板管理查询分类
	@RequestMapping("baikeCategoryQueryJurisdiction")
	public void tobaikeCategoryQueryDepartment(HttpServletResponse response)
			throws Exception {

		List<BaikeCategory> list = baikeService.getBaikeCategory();
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		for (int i = 0; i < list.size(); i++) {
			BaikeCategory baikeCategory = list.get(i);
			mp = new LinkedHashMap<String, Object>();
			mp.put("id", baikeCategory.getId());
			mp.put("name", baikeCategory.getNameZh());
			mp.put("pId", baikeCategory.getPid());
			mp.put("sid", baikeCategory.getSid());
			r.add(mp);
		}
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	// 知识百科管理 -->模板管理分类列表查询右侧
	@RequestMapping("baikeCategoryQueryUser")
	public void toBaikeTemplateQueryUser(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		int id = Integer.parseInt(request.getParameter("id"));
		BaikeCategory baikeCategory=baikeService.findBaikeCategory(id);
		
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		HashMap<String, Object> queryParams=new LinkedHashMap<String, Object>();
		queryParams.put("=,sid", baikeCategory.getSid());
		List<BaikeTemplate> list = baikeService.getBaikeTemplate(queryParams, 1, 10);
		for (int i = 0; i < list.size(); i++) {
			BaikeTemplate baikeTemplate = list.get(i);
				mp = new LinkedHashMap<String, Object>();
				mp.put("id", baikeTemplate.getId());
				mp.put("name", baikeTemplate.getNameZh());
				mp.put("pId", baikeTemplate.getPid());
				r.add(mp);
		}
		/*//设置父节点
		LinkedHashMap<String, Object> mps = new LinkedHashMap<String, Object>();
		mps.put("id", baikeCategory.getId());
		mps.put("name", baikeCategory.getNameZh());
		mps.put("pId", baikeCategory.getPid());
		r.add(mps);*/
		String resultString = formatToJson(r);
		super.pringWriterToPage(resultString, "application/json", response);
	}

	// 知识百科管理 -->模板管理分类列表右侧新增
	@RequestMapping("baikeTemplateAddMentRight")
	public void toBaikeTemplateAddMentRight(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String nameEn = request.getParameter("nameEn");
		String nameZh = request.getParameter("nameZh");
		String sid = request.getParameter("sid");
		String sort = request.getParameter("sort");
		String pid = request.getParameter("pid");
		BaikeTemplate baikeTemplate = new BaikeTemplate();
		baikeTemplate.setNameEn(nameEn);
		baikeTemplate.setNameZh(nameZh);
		baikeTemplate.setSid(sid);
		baikeTemplate.setSort(Integer.parseInt(sort));
		baikeTemplate.setPid(Integer.parseInt(pid));

		baikeService.saveBaikeTemplate(baikeTemplate);

		String result = formatToJson(baikeTemplate);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识百科管理 -->模块管理-->修改右侧
	@RequestMapping("baikeTemplateUploadMent")
	public void tobaikeTemplateUploadMent(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		String nameEn = request.getParameter("nameEn");
		String nameZh = request.getParameter("nameZh");
		String sid = request.getParameter("sid");
		int sort = Integer.parseInt(request.getParameter("sort"));
		int pid = Integer.parseInt(request.getParameter("pid"));
		BaikeTemplate baikeTemplate = baikeService.findBaikeTemplate(id);
		baikeTemplate.setNameZh(nameZh);
		baikeTemplate.setNameEn(nameEn);
		baikeTemplate.setSort(sort);
		baikeTemplate.setSid(sid);
		baikeTemplate.setPid(pid);
		baikeService.editBaikeTemplate(baikeTemplate);

		String result = formatToJson(baikeTemplate);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识百科管理 -->模块管理-->修改右侧查询方法
	@RequestMapping("baikeTemplateUploadEditMent")
	public void tobBaikeTemplateUploadEditMent(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		BaikeTemplate baikeTemplate = baikeService.findBaikeTemplate(id);
		LinkedHashMap<String, Object> mp = new LinkedHashMap<String, Object>();
		
		HashMap<String, Object> queryParams=new LinkedHashMap<String, Object>();
		queryParams.put("pid", baikeTemplate.getPid());
		if(0 == baikeTemplate.getPid()){
			mp.put("parentName", "根节点");
		}else{
			mp.put("parentName", baikeService.findBaikeTemplate(baikeTemplate.getPid()).getNameZh());
		}
		mp.put("pid", baikeTemplate.getPid());
		mp.put("nameEn", baikeTemplate.getNameEn());
		mp.put("sid", baikeTemplate.getSid());
		mp.put("nameZh", baikeTemplate.getNameZh());
		mp.put("sort", baikeTemplate.getSort());
		String result = formatToJson(mp);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识百科管理 -->模块管理-->删除右侧菜单
	@RequestMapping("baikeTemplateDeleteMent")
	public void toBaikeTemplateDeleteMent(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		int id = Integer.parseInt(request.getParameter("id"));
		BaikeTemplate baikeTemplate = baikeService.findBaikeTemplate(id);

		baikeService.deleteBaikeTemplate(baikeTemplate);

		String result = formatToJson(baikeTemplate);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	// 知识百科管理 -->模块管理-->查询根目錄菜单
	@RequestMapping("baikeTemplateQueryMent")
	public void toBaikeTemplateQueryMent(HttpServletRequest request,HttpServletResponse response)
			throws Exception {
		String id = request.getParameter("id");
		List<HashMap<String, Object>> r =null;
		if(id != null && !"".equals(id) && !"undefined".equals(id)){
			HashMap<String, Object> queryParams=new LinkedHashMap<String, Object>();
			BaikeTemplate bTemplate = baikeService.findBaikeTemplate(Integer.parseInt(id));
			queryParams.put("=,sid", bTemplate.getSid());
			List<BaikeTemplate> list = baikeService.getBaikeTemplate(queryParams, 1, 10);
			r = new ArrayList<HashMap<String, Object>>();
			LinkedHashMap<String, Object> mp = null;
			for (int i = 0; i < list.size(); i++) {
				BaikeTemplate baikeTemplate = list.get(i);
				mp = new LinkedHashMap<String, Object>();
				mp.put("id", baikeTemplate.getId());
				mp.put("name", baikeTemplate.getNameZh());
				mp.put("pId", baikeTemplate.getPid());
				r.add(mp);
			}
		}
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}

	// 知识百科管理 -->词条查询-->列表查询
	@RequestMapping("baikeEntryFindAll")
	@ResponseBody
	public void toBaikeEntryFindAll(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
	//	int id = Integer.parseInt(request.getParameter("id"));
		Integer pageNumber = 15;
		Integer pageSize = Integer.parseInt(request.getParameter("page"));
		String text = request.getParameter("text");
		HashMap<String, Object> queryParams = new HashMap<String, Object>();
		if(text != null && !"".equals(text)){
			queryParams.put("%,title", text);
		}
		queryParams.put("^,date", "desc");
		Integer count = baikeService.getBaikeEntryCount(queryParams);
		List<HashMap<String, Object>> r = new ArrayList<HashMap<String, Object>>();
		LinkedHashMap<String, Object> mp = null;
		List<BaikeEntry> list = baikeService.getBaikeEntry(queryParams,
				pageSize, pageNumber);
		for (int i = 0; i < list.size(); i++) {
			BaikeEntry baikeEntry = list.get(i);
			mp = new LinkedHashMap<String, Object>();
			mp.put("id", baikeEntry.getId());
			mp.put("sid", baikeEntry.getSid());
			mp.put("title", baikeEntry.getTitle());
			mp.put("descriptionImg", baikeEntry.getDescriptionImg());
			mp.put("description", baikeEntry.getDescription());
			mp.put("basicText", baikeEntry.getBasicText());
			mp.put("mainText", baikeEntry.getMainText());
			mp.put("photoAlbum", baikeEntry.getPhotoAlbum());
			mp.put("source", baikeEntry.getSource());
			mp.put("date", baikeEntry.getDate());
			mp.put("referenceMaterial", baikeEntry.getReferenceMaterial());
			mp.put("relationship", baikeEntry.getRelationship());
			mp.put("author", baikeEntry.getAuthor());
			mp.put("IpAddress", baikeEntry.getIpAddress());
			mp.put("version", baikeEntry.getVersion());
			String dateTime = "null";
			if (baikeEntry.getDate() != null
					&& !baikeEntry.getDate().equals("")) {
				dateTime = baikeEntry.getDate();
			}
			mp.put("date", dateTime);
			r.add(mp);
		}

		String result = formatToJson(r);
		StringBuffer sb = new StringBuffer();
		int listsize = r.size();
		sb.append("{\"listsize\":" + listsize + ",");
		sb.append("\"pageSize\":"
				+ (int) Math.ceil(Double.valueOf(count) / pageNumber) + ",");
		sb.append("\"result\":" + result);
		sb.append("}");
		super.pringWriterToPage(sb.toString(), "application/json", response);
	}
	// 知识百科管理 -->词条管理-->删除
	@RequestMapping("entryOrganizationmemberDel")
	public void entryOrganizationmemberDel(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String id = request.getParameter("id");
		BaikeEntry baikeEntry = baikeService.findBaikeEntry(id);
		
		baikeService.deleteBaikeEntry(baikeEntry);
		
		String result = formatToJson(baikeEntry);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	
	// 知识百科管理 -->新闻管理-->查询
	@RequestMapping("queryBaiKeNews")
	public void queryBaiKeNews(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String page = request.getParameter("page");
		String title = request.getParameter("title");
		String source = request.getParameter("source");
		String submitUser = request.getParameter("submitUser");
		String status = request.getParameter("status");
		//路径
		String uploadPath =  XxlConfClient.get("dal.file.server", "") +"/";
		HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
		if(title != null && !"".equals(title)){
			queryParams.put("%,title", title);
		}
		if(source != null && !"".equals(source)){
			queryParams.put("%,source", source);
		}
		if(submitUser != null && !"".equals(submitUser)){
			queryParams.put("%,submit_user", submitUser);
		}
		if(status != null && !"".equals(status)){
			queryParams.put("=,status", status);
		}
		queryParams.put("^,submit_time", "desc");
		List<BaikeNews> BaikeNewsList = baikeService.getBaikeNews(queryParams, Integer.parseInt(page), 15);
		for (int i = 0; i < BaikeNewsList.size(); i++) {
			BaikeNews baikeNews = BaikeNewsList.get(i);
			if(baikeNews.getCoverImg() != null && !"".equals(baikeNews.getCoverImg())){
				baikeNews.setCoverImg(uploadPath +baikeNews.getCoverImg());
			}
		}
		int count = baikeService.getBaikeNewsCount(queryParams);
		int ye =(int)Math.ceil(Double.valueOf(count)/15);
		HashMap<String, Object> conditions = new HashMap<String, Object>();
		conditions.put("news", BaikeNewsList);
		conditions.put("ye", ye);
		String result = formatToJson(conditions);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	// 知识百科管理 -->新闻管理-->新增或修改
	@RequestMapping("addBaikeNews")
	public void addBaikeNews(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String title = request.getParameter("title");
		String summary = request.getParameter("summary");
		String coverImg = request.getParameter("coverImg");
		String submitTime = request.getParameter("submitTime");
		String source = request.getParameter("source");
		String submitUser = request.getParameter("submitUser");
		String status = request.getParameter("status");
		String text = request.getParameter("text");
		String id = request.getParameter("id");
		
		BaikeNews baikeNews = new BaikeNews();
		baikeNews.setSource(source);
		baikeNews.setStatus(Integer.parseInt(status));
		baikeNews.setSubmitTime(submitTime);
		baikeNews.setSubmitUser(submitUser);
		baikeNews.setSummary(summary);
		baikeNews.setTitle(title);
		List<String> r = new ArrayList<String>();
		String areturn="yes";
		try {
			if(id != null && !"".equals(id)){
				baikeNews.setId(Integer.parseInt(id));
				//获取服务器地址
				String serversPath =  XxlConfClient.get("dal.file.server", "");
				coverImg = coverImg.replaceAll(serversPath, "");
				baikeNews.setText(text.replaceAll(serversPath, ""));
				baikeNews.setCoverImg(coverImg);
				baikeService.editBaikeNews(baikeNews);
			}else{
				//获取服务器地址
				String serversPath =  XxlConfClient.get("dal.file.server", "")+"/";
				coverImg = coverImg.replaceAll(serversPath, "");
				baikeNews.setText(text.replaceAll(serversPath, ""));
				baikeNews.setCoverImg(coverImg);
				baikeService.saveBaikeNews(baikeNews);
			}
		} catch (Exception e) {
			areturn = "no";
			e.printStackTrace();
		}
		r.add(areturn);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	// 知识百科管理 -->新闻管理-->修改
	@RequestMapping("uploadBaikeNews")
	public void uploadBaikeNews(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		//获取服务器地址
		String serversPath =  XxlConfClient.get("dal.file.server", "");
		String id =request.getParameter("id");
		BaikeNews baikeNews = baikeService.findBaikeNews(id);
		baikeNews.setCoverImg(serversPath+baikeNews.getCoverImg());
		baikeNews.setText(CommonUrl.addPrefixPath("src", baikeNews.getText(), serversPath+"/"));
		String result = formatToJson(baikeNews);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	// 知识百科管理 -->新闻管理-->删除
	@RequestMapping("deleteBaikeNews")
	public void deleteBaikeNews(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String id =request.getParameter("id");
		List<String> r = new ArrayList<String>();
		String rString ="yes";
		try {
			BaikeNews baikeNews = baikeService.findBaikeNews(id);
			baikeService.deleteBaikeNews(baikeNews);
		} catch (Exception e) {
			rString = "no";
			e.printStackTrace();
		}
		r.add(rString);
		String result = formatToJson(r);
		super.pringWriterToPage(result.toString(), "application/json", response);
	}
	// 知识百科管理 -->查询历史版本
	@RequestMapping("queryBaiKeHistory")
	public void queryBaiKeHistory(HttpServletRequest request,
	        HttpServletResponse response) throws Exception {
	    String historyId =request.getParameter("historyId");
	    String curr =request.getParameter("curr");
	    LinkedHashMap<String, Object> r = new LinkedHashMap<String, Object>();
	    HashMap<String, Object> queryParams = new LinkedHashMap<String, Object>();
	    queryParams.put("=,baike_entry_id", historyId);
	    //总数
	    Integer much = baikeService.getBaikeEntryVersionCount(queryParams);
	    int page=(int)Math.ceil(Double.valueOf(much)/10);;
	    //数据
	    List<BaikeEntryVersion> BaikeEntryVersionLsit = baikeService.getBaikeEntryVersion(queryParams, Integer.parseInt(curr), 10);
	    r.put("much", much);
	    r.put("page", page);
	    r.put("BaikeEntryVersion", BaikeEntryVersionLsit);
	    String result = formatToJson(r);
	    super.pringWriterToPage(result.toString(), "application/json", response);
	}
}
